<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>宿舍管理系统</title>
    <meta name="renderer" content="webkit">
    <meta name="csrf-token" content="{{ csrf_token() }}"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="{{asset('css/font.css')}}">
    <link rel="stylesheet" href="{{asset('css/xadmin.css')}}">
    <script src="{{asset('lib/layui/layui.js')}}" charset="utf-8"></script>
    <script type="text/javascript" src="{{asset('js/xadmin.js')}}"></script>
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <table class="layui-table layui-form">
                        <thead>
                        <tr>
                            {{--<th>ID</th>--}}
                            <th>宿舍</th>
                            <th>费用类型</th>
                            <th>入住天数</th>
                            <th>宿舍总人天</th>
                            <th>用量</th>
                            <th>总费用</th>
                            <th>承担费用</th>
                            {{--<th>操作</th>--}}
                        </thead>
                        <tbody>
                        @foreach($staffPeriodFeeDetails as $staffPeriodFeeDetail)
                            <tr>
{{--                                <td>{{$staffPeriodFeeDetail->id}}</td>--}}
                                <td>{{$staffPeriodFeeDetail->dorm->code}}</td>
                                @if($staffPeriodFeeDetail->fee_type=="App\Models\DepositFeeType")
                                    <td>押金</td>
                                    @else
                                    @foreach($feeTypes as $feeType)
                                        @if($feeType->model==$staffPeriodFeeDetail->fee_type)
                                            <td>{{$feeType->cn_name}}</td>
                                        @endif
                                    @endforeach
                                @endif
                                <td>{{$staffPeriodFeeDetail->staff_person_days}}</td>
                                <td>{{$staffPeriodFeeDetail->dorm_person_days}}</td>
                                <td>{{$staffPeriodFeeDetail->total_resource_consume}}</td>
                                <td>{{$staffPeriodFeeDetail->total_money}}</td>
                                <td>{{$staffPeriodFeeDetail->fee_undertake}}</td>
                                {{--<td><button class="layui-btn layui-btn-xs" onclick="detail_del(this,'{{$staffPeriodFeeDetail->id}}')">删除</button></td>--}}
                            </tr>
                        @endforeach
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    function detail_del(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            //发异步删除数据
            del_one(obj,id);
        });
    }

    function del_one(obj, id) {
        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });
        $.ajax({
            url: 'staff-period-fee-details/' + id,
            type: 'DELETE',
            dataType: "json",
            success: function (d) {
                if(d.error){
                    layer.msg('删除失败:'+d.message, {icon: 2, time: 1000});
                }else{
                    layer.msg(`已删除${id}!`, {icon: 1, time: 1000});
                }

                if(obj){
                    $(obj).parents("tr").remove();
                }
            },
            error: function (err) {
                console.log(err);
                layer.msg('删除失败', {icon: 2, time: 1000});
            }
        });
    }
</script>
</html>